<?php
/**
 * Created by PhpStorm.
 * 售后工单
 * User: ciacm
 * Date: 2017/5/19
 * Time: 14:01
 */

namespace SDXApi\Model;


use Think\Model;

class WorkorderContentModel extends Model {


    /**
     * 添加工单内容
     * Created By caicm
     * @param int $workorder_id
     * @param string $content
     * @param int $status
     * @param string $created
     * @param int $role
     * @return mixed
     */
    public function add_workorder_content($workorder_id=0, $content='', $status=1, $created='', $role=1){

        $data = array(
            'workorder_id' => $workorder_id,
            'role' => $role,
            'status' => $status,
            'content' => $content,
            'created' => $created,
            'add_time' => gmtime()
        );

        return $this->data($data)->add();

    }

    /**
     * 获取工单回复内容数量
     * Created By caicm
     * @param int $workorder_id
     * @return mixed
     */
    public function get_reply_workorder_count($workorder_id=0){

        $where = array(
            'workorder_id' => $workorder_id,
            'role' => 2
        );

        return $this->where($where)->count();

    }

    /**
     * 绑定上传图片
     * Created By caicm
     * @param string $id_list
     * @param int $workorder_content_id
     * @return bool
     */
    public function update_workorder_img($id_list='', $workorder_content_id=0){

        $where = array(
            'img_id' => array('in', $id_list)
        );

        $data = array(
            'workorder_content_id' => $workorder_content_id
        );

        return M('workorder_content_img')->where($where)->data($data)->save();

    }

    /**
     * 获取订单内容列表
     * Created By caicm
     * @param int $workorder_id
     * @return mixed
     */
    public function get_content_list($workorder_id=0){

        $where = array(
            'workorder_id' => $workorder_id
        );

        return $this->field('id,content,role,add_time,status')->where($where)->order('id asc')->select();

    }

    /**
     * 获取订单内容图片列表
     * Created By caicm
     * @param int $workorder_content_id
     * @return mixed
     */
    public function get_content_img($workorder_content_id=0){

        $where = array(
            'workorder_content_id' => $workorder_content_id
        );

        return M('workorder_content_img')->field('img_name')->where($where)->select();

    }

}